"""
私有化装饰器：
    先get后set：
        @property
        @age.setter
"""


class Student:
    def __init__(self, name, age):
        self.__name = name
        self.__age = age
        self.__score = 50

    def __str__(self):
        return "姓名是：" + self.__name + ",年龄：" + str(self.__age) + ",分数：" + str(self.__score)

    # 先定义get_age
    @property
    def age(self):
        return self.__age

    # 再定义set_age；依赖于get
    @age.setter
    def age(self, age):
        if age < 0 or age > 120:
            print("年龄没有在合理范围内")
        else:
            self.__age = age

    """
    # 定义公有的get和set方法
    def set_age(self, age):
        if age < 0 or age > 120:
            print("年龄没有在合理范围内")
        else:
            self.__age = age

    def get_age(self):
        return self.__age

    def set_score(self, score):
        self.__score = score

    def set_name(self, name):
        if len(name) > 6:
            print("名字长度不能超过六位")
        else:
            self.__name = name

    def get_name(self):
        return self.__name
    """


s = Student("lily", 30)

s.age = 131
result = s.age  # 因为加了装饰器，可以像使用name一样

print(result)

print(dir(s))
